scale: Add a destroy notify to set_format_value_func
authorTimm Bäder <mail@baedert.org>
Thu, 15 Aug 2019 15:21:47 +0000 (17:21 +0200)
committerTimm Bäder <mail@baedert.org>
Thu, 15 Aug 2019 15:21:47 +0000 (17:21 +0200)
Closes #2098

demos/widget-factory/widget-factory.c
gtk/gtkscale.c
gtk/gtkscale.h

index 50bcc8c600139f97bad6c16c8d47d1a6017378af..781f63f7cd14dd00530dffc25d58397a14e09230 100644 (file)
@@ -1944,10 +1944,10 @@ activate (GApplication *app)
   g_timeout_add (100, (GSourceFunc)pulse_it, widget);
 
   widget = (GtkWidget *)gtk_builder_get_object (builder, "scale3");
-  gtk_scale_set_format_value_func (GTK_SCALE (widget), scale_format_value, NULL);
+  gtk_scale_set_format_value_func (GTK_SCALE (widget), scale_format_value, NULL, NULL);
 
   widget = (GtkWidget *)gtk_builder_get_object (builder, "scale4");
-  gtk_scale_set_format_value_func (GTK_SCALE (widget), scale_format_value_blank, NULL);
+  gtk_scale_set_format_value_func (GTK_SCALE (widget), scale_format_value_blank, NULL, NULL);
 
   widget = (GtkWidget *)gtk_builder_get_object (builder, "box_for_context");
   model = (GMenuModel *)gtk_builder_get_object (builder, "new_style_context_menu_model");
index c7922e859173b34d8ec78d4a9bd2819bf80b1d48..fafcfab3bb57380453452a1d0ec479525e50f5bc 100644 (file)
@@ -150,6 +150,7 @@ struct _GtkScalePrivate
 
   GtkScaleFormatValueFunc format_value_func;
   gpointer format_value_func_user_data;
+  GDestroyNotify format_value_func_destroy_notify;
 
   guint         draw_value : 1;
   guint         value_pos  : 2;
@@ -1553,6 +1554,9 @@ gtk_scale_finalize (GObject *object)
 
   g_clear_pointer (&priv->value_widget, gtk_widget_unparent);
 
+  if (priv->format_value_func_destroy_notify)
+    priv->format_value_func_destroy_notify (priv->format_value_func_user_data);
+
   G_OBJECT_CLASS (gtk_scale_parent_class)->finalize (object);
 }
 
@@ -2040,6 +2044,7 @@ gtk_scale_buildable_custom_finished (GtkBuildable *buildable,
  * @scale: a #GtkScale
  * @func: (nullable): function that formats the value
  * @user_data: (nullable): user data to pass to @func
+ * @destroy_notify: (nullable): destroy function for @user_data
  *
  * @func allows you to change how the scale value is displayed. The given
  * function will return an allocated string representing @value.
@@ -2051,7 +2056,8 @@ gtk_scale_buildable_custom_finished (GtkBuildable *buildable,
 void
 gtk_scale_set_format_value_func (GtkScale                *scale,
                                  GtkScaleFormatValueFunc  func,
-                                 gpointer                 user_data)
+                                 gpointer                 user_data,
+                                 GDestroyNotify           destroy_notify)
 {
   GtkScalePrivate *priv = gtk_scale_get_instance_private (scale);
   GtkAdjustment *adjustment;
@@ -2059,8 +2065,12 @@ gtk_scale_set_format_value_func (GtkScale                *scale,
 
   g_return_if_fail (GTK_IS_SCALE (scale));
 
+  if (priv->format_value_func_destroy_notify)
+    priv->format_value_func_destroy_notify (priv->format_value_func_user_data);
+
   priv->format_value_func = func;
   priv->format_value_func_user_data = user_data;
+  priv->format_value_func_destroy_notify = destroy_notify;
 
   if (!priv->value_widget)
     return;
index c18a82ecff685f4d8cfe5b9687b4dbf0696a3033..36f5fc2bfce7310fbeed941f5bd9f6c9a1eb3dfc 100644 (file)
@@ -128,7 +128,8 @@ void              gtk_scale_clear_marks        (GtkScale        *scale);
 GDK_AVAILABLE_IN_ALL
 void              gtk_scale_set_format_value_func (GtkScale                *scale,
                                                    GtkScaleFormatValueFunc  func,
-                                                   gpointer                 user_data);
+                                                   gpointer                 user_data,
+                                                   GDestroyNotify           destroy_notify);
 
 G_END_DECLS